package bar.dark.lee.stats;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;

import org.achartengine.ChartFactory;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

import bar.dark.lee.BDConstents;
import bar.dark.lee.R;
import bar.dark.lee.SuperActivity;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.common.DBSQLite;
import bar.dark.lee.common.DBSQLite.ParseSelectData;
import bar.dark.lee.manager.card.CreditCardResultDateData;
import bar.dark.lee.manager.card.CreditCardUpdateActivity;
import bar.dark.lee.setting.TipInfoActivity;
import bar.dark.lee.setting.TipsActivity;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.SyncStateContract.Columns;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.TableRow;
import android.widget.TextView;

public class StatsCategoryActivity extends SuperActivity
{
	public static final String STATS_CATEGORY_DATA = "stats_category_data";
	
	private DBSQLite sql;
	private int [] colors;
	private ArrayList<String> tempNames;
	private String [] names;
	private ArrayList<Double> tempValues;
	private double[] values;
	private ArrayList<StatsCategoryData> list;
	
	private ViewGroup graphLayout;
	
	private View leftDateButton;
	private View rightDateButton;
	private TextView dateTextView;
	
	private View statsCategoryListButton;
	
	private String colunmName = "";
	
	private int year;
	private int month;
	private int date;
	
	private int inoutFlag;
	
	private int typeFlag = 0;
	private int assetFlag = 0;
	
	private ArrayList<String> moneyKinds = new ArrayList<String>();

	private ArrayList<CreditCardResultDateData> creditResultList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		sql = DBSQLite.getInstance(this);
		
		setFindView();
		setClickListener();
		
		Intent intent = getIntent();
		
		inoutFlag = intent.getIntExtra(StatsActivity.STATS_CATEGORY_FLAG, -1);
		
		if (inoutFlag != -1)
		{
			setData(inoutFlag);
		}
	}

	private void setFindView()
	{
		setContentView(R.layout.stats_category_activity);
		
		graphLayout = (ViewGroup) findViewById(R.id.statsCategoryGraphLayout);
		leftDateButton = findViewById(R.id.statsCategoryDateLeftButton);
		rightDateButton = findViewById(R.id.statsCategoryDateRightButton);
		dateTextView = (TextView) findViewById(R.id.statsCategoryDateText);
		statsCategoryListButton = findViewById(R.id.statsCategoryListButton);
		
		Calendar cal = Calendar.getInstance();
		year = cal.get(Calendar.YEAR);
		month = cal.get(Calendar.MONTH);
		date = cal.get(Calendar.DAY_OF_MONTH);
		
		// 달 시작일 가져온다
    	SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
    	int startDate = Integer.parseInt(pref.getString(BDConstents.START_DATE, "1"));
    	
		if (date < startDate)
		{
			if (month == 0)
			{
				year--;
				month = 11;
			}
			else
			{
				month--;
			}
			
			dateTextView.setText(year + "년 " + (month+1) + "월");
		}
		else
		{
			dateTextView.setText(year + "년 " + (month+1) + "월");
		}
	}
	
	private void setClickListener()
	{
		leftDateButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startLeftMonthButton();
			}
		});
		
		rightDateButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startRightMonthButton();
			}
		});
		
		statsCategoryListButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(StatsCategoryActivity.this, StatsCategoryListActivity.class);
				intent.putExtra(STATS_CATEGORY_DATA, list);
				intent.putExtra(StatsActivity.STATS_CATEGORY_FLAG, inoutFlag);
				intent.putExtra(StatsActivity.SELECT_YEAR, year);
				intent.putExtra(StatsActivity.SELECT_MONTH, month);
				intent.putExtra(StatsAssetActivity.TYPE_FLAG, typeFlag);
				intent.putExtra(StatsAssetActivity.ASSET_FLAG, assetFlag);
				startActivity(intent);
			}
		});
	}

	private void setData(int flag)
	{
		// 데이터를 셋팅 하기 전에 뷰를 전부 지워준다.
		if (graphLayout.getChildCount() > 0)
		{
			graphLayout.removeAllViews();
		}
		
		if (flag == StatsActivity.STATS_IN)
		{
			colunmName = "inmoney";
			setTitle("수입 카테고리");
		}
		else if (flag == StatsActivity.STATS_OUT)
		{
			colunmName = "outmoney";
			setTitle("지출 카테고리");
		}
		else if (flag == StatsActivity.STATS_MOVE)
		{
			colunmName = "outmoney";
			setTitle("이동 카테고리");
		}
		else if (flag == StatsActivity.STATS_ASSET_MANAGER)
		{
			int type = getIntent().getIntExtra(StatsAssetActivity.TYPE_FLAG, 0);
			int asset = getIntent().getIntExtra(StatsAssetActivity.ASSET_FLAG, 0);
			
			String typeStr = "";
			String assetStr = "";
			
			if (type == 0)
			{
				typeStr = "지출";
			}
			else if (type ==1)
			{
				typeStr = "수입";
			}
			else if (type ==2)
			{
				typeStr = "이동";
			}
			
			if (asset == 0)
			{
				assetStr = "통장";
			}
			else if (asset == 1)
			{
				assetStr = "체크카드";
			}
			else if (asset == 2)
			{
				assetStr = "신용카드";
			}
			else if (asset == 3)
			{
				assetStr = "현금";
			}
			
			setTitle(typeStr + " / " + assetStr);
		}
		
		new ShowDialog().execute(0);
	}

	private void setStatsData()
	{
		if (list.size() <= 0)
		{
			View noDataView = getLayoutInflater().inflate(R.layout.view_no_result, null);
			graphLayout.addView(noDataView);
			return;
		}
		
//		int totalMoney = 0;
		BigDecimal totalMoney = BigDecimal.ZERO;
		for (int i = 0; i < list.size(); i++)
		{
//			totalMoney = totalMoney + list.get(i).getMoney();
			totalMoney = totalMoney.add(new BigDecimal(list.get(i).getMoney()));
		}
		
		tempValues = new ArrayList<Double>();
		tempNames = new ArrayList<String>();
		names = new String[list.size()];
		values = new double[list.size()];
		
		String type = "###.00";
		DecimalFormat df = new DecimalFormat(type); 
		
		for (int i = 0; i < list.size(); i++)
		{
			values[i] = Double.parseDouble(df.format((double)(new BigDecimal(list.get(i).getMoney()).doubleValue()) 
					/ (double)(totalMoney.doubleValue()) * 100));
			
			list.get(i).setPercent(values[i] + "");
			
			if (inoutFlag == StatsActivity.STATS_ASSET_MANAGER)
			{
				names[i] = list.get(i).getMoneyKind() + "(" + values[i] + "%)";
			}
			else 
			{
				names[i] = list.get(i).getCategory() + "(" + values[i] + "%)";
			}
		}
		
		double tempValue;
		String tempString;
		
		for (int i = values.length-1; i >= 0; i--)
		{
			for (int j = 0; j < i; j++)
			{
				if (values[j] < values[j+1])
				{
					tempValue = values[j+1];
					values[j+1] = values[j];
					values[j] = tempValue;
					
					tempString = names[j+1];
					names[j+1] = names[j];
					names[j] = tempString;
				}
			}
		}
		
		int [] color = new int[list.size()];
		
		for (int i = 0; i < color.length; i++)
		{
			color[i] = Color.rgb(Math.round((float)(Math.random() * 255)), Math.round((float)(Math.random() * 255)), Math.round((float)(Math.random() * 255)));
			//color[i] = colorCategory[(int) (Math.random() * colorCategory.length)];
		}
		
		DefaultRenderer renderer = new DefaultRenderer();
		renderer.setLabelsTextSize(20);
		renderer.setLegendTextSize(20);
		renderer.setLabelsColor(Color.BLACK);
	    renderer.setZoomButtonsVisible(false);
	    renderer.setZoomEnabled(true);
	    renderer.setPanEnabled(true);
	    renderer.setChartTitleTextSize(20);
	    		
	    for (int col : color) 
	    {
		     SimpleSeriesRenderer r = new SimpleSeriesRenderer();
		     r.setColor(col);
		     renderer.addSeriesRenderer(r);
	    }
	    
	    CategorySeries series = new CategorySeries("");
	    
	    for (int i = 0; i < names.length; i++)
		{
	    	series.add(names[i], values[i]);
		}
	    
	    View view = ChartFactory.getPieChartView(this, series, renderer);
	    
	    graphLayout.addView(view);
	}

	private void getCategoryData()
	{
//		String query = "";
		list = new ArrayList<StatsCategoryData>();
		
		// 달 시작일 가져온다
    	SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
    	int startDate = Integer.parseInt(pref.getString(BDConstents.START_DATE, "1"));
    	
    	String inOutQuery = "";
    	
    	String firstDate = "";
    	String lastDate = "";
    	
    	if (startDate == 1) 
		{
			firstDate = BDUtil.getDateDB(year, month+1, 00);
			lastDate = BDUtil.getDateDB(year, month+1, 32);
		}
		else
		{
			if (month+1 == 1)
			{
				firstDate = BDUtil.getDateDB(year, 1, startDate);
				lastDate = BDUtil.getDateDB(year, 2, startDate-1);
			}
			else if (month+1 == 12)
			{
				firstDate = BDUtil.getDateDB(year, 12, startDate);
				lastDate = BDUtil.getDateDB(year+1, 1, startDate-1);
			}
			else
			{
				firstDate = BDUtil.getDateDB(year, month+1, startDate);
				lastDate = BDUtil.getDateDB(year, month+2, startDate-1);
				
			}
		}
    	
		if (inoutFlag == StatsActivity.STATS_IN)
		{
			inOutQuery = "SELECT category, SUM(" + colunmName + 
					") money FROM in_out WHERE " + colunmName + " not in ('0') and date >= " +
					firstDate + " and date <= " +
					lastDate + " and type not in (" + 
					BDConstents.INOUT_TYPE + ", " +
					BDConstents.OUTIN_TYPE + ", " +
					BDConstents.MYBANK_INOUT_TYPE + 
					") GROUP BY category;";
			
			sql.selectMapTile(this, inOutQuery, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int categoryIdx = c.getColumnIndex("category");
					int moneyIdx = c.getColumnIndex("money");
					
					BigDecimal money = BigDecimal.ZERO;
					String name = "";
					
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = c.getString(categoryIdx);
						money = new BigDecimal(c.getString(moneyIdx));
						data.setCategory(name);
						data.setMoney(money.toString());
						list.add(data);
						
						c.moveToNext();
					}
					
				}
			});
		}
		else if(inoutFlag == StatsActivity.STATS_OUT)
		{
			inOutQuery = "SELECT category, SUM(" + colunmName + 
					") omoney, SUM(postmoney) pmoney FROM in_out WHERE " +
					"inmoney in ('0') and (outmoney not in ('0') or postmoney not in ('0')) and date >= " +
					firstDate + " and date <= " +
					lastDate + " and type not in (" + 
					BDConstents.INOUT_TYPE + ", " +
					BDConstents.OUTIN_TYPE + ", " +
					BDConstents.MYBANK_INOUT_TYPE + ") " +
					"and category not in ('" + 
					BDConstents.CATEGORY_POST_OUT +
					"') GROUP BY category "
					+ "UNION ALL "
					+ "SELECT category, SUM(" + colunmName + 
					") omoney, SUM(postmoney) pmoney FROM in_out WHERE date >= " +
					firstDate + " and date <= " +
					lastDate + " and category in ('" 
					+ BDConstents.CATEGORY_SUSUMONEY + "') GROUP BY category";
			
			sql.selectMapTile(this, inOutQuery, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int categoryIdx = c.getColumnIndex("category");
					int moneyIdx = c.getColumnIndex("omoney");
					int pmoneyIdx = c.getColumnIndex("pmoney");
					
					BigDecimal money = BigDecimal.ZERO;
					BigDecimal pmoney = BigDecimal.ZERO;
					String name = "";
										
					
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = c.getString(categoryIdx);
						money = new BigDecimal(c.getString(moneyIdx));
						pmoney = new BigDecimal(c.getString(pmoneyIdx));
						data.setCategory(name);
						data.setMoney(money.add(pmoney).toString());
						list.add(data);
						
						c.moveToNext();
					}
				}
			});
		}
		else if (inoutFlag == StatsActivity.STATS_MOVE)
		{
			inOutQuery = "SELECT category, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
					"FROM in_out WHERE date >= " +
					firstDate + " and date <= " +
					lastDate + " and type = " + 
					BDConstents.INOUT_TYPE + 
					" GROUP BY category;";
			
			sql.selectMapTile(this, inOutQuery, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int categoryIdx = c.getColumnIndex("category");
					int omoneyIdx = c.getColumnIndex("omoney");
					int pmoneyIdx = c.getColumnIndex("pmoney");
					
					BigDecimal omoney = BigDecimal.ZERO;
					String name = "";
										
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = c.getString(categoryIdx);
						omoney = new BigDecimal(c.getString(omoneyIdx));
						omoney = omoney.add(new BigDecimal(c.getString(pmoneyIdx)));
						data.setCategory(name);
						
						data.setMoney(omoney.toString());
						list.add(data);
						
						c.moveToNext();
					}
				}
			});
			
			inOutQuery = "SELECT category, SUM(inmoney) imoney " +
					"FROM in_out WHERE date >= " +
					firstDate + " and date <= " +
					lastDate + " and type = " + 
					BDConstents.OUTIN_TYPE + 
					" GROUP BY category;";
			
			sql.selectMapTile(this, inOutQuery, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int categoryIdx = c.getColumnIndex("category");
					int imoneyIdx = c.getColumnIndex("imoney");
					
					BigDecimal imoney = BigDecimal.ZERO;
					String name = "";
										
					
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = c.getString(categoryIdx);
						imoney = new BigDecimal(c.getString(imoneyIdx));
						data.setCategory(name);
						
						data.setMoney(imoney.toString());
						
						boolean flag = false;
						
						for (int j = 0; j < list.size(); j++)
						{
							if (data.getCategory().equals(list.get(j).getCategory()))
							{
								BigDecimal tempMoney = new BigDecimal(list.get(j).getMoney());
								
								list.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
								
								flag = true;
							}
						}
						
						if (flag == false)
						{
							list.add(data);
						}
						
						c.moveToNext();
					}
				}
			});
			
			inOutQuery = "SELECT type, category, SUM(outmoney) omoney, " +
					"SUM(inmoney) imoney, SUM(postmoney) pmoney " +
					"FROM in_out WHERE date >= " +
					firstDate + " and date <= " +
					lastDate + " and type = " + 
					BDConstents.MYBANK_INOUT_TYPE + 
					" GROUP BY category;";
			
			sql.selectMapTile(this, inOutQuery, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int categoryIdx = c.getColumnIndex("category");
					int omoneyIdx = c.getColumnIndex("omoney");
					int pmoneyIdx = c.getColumnIndex("pmoney");
					int imoneyIdx = c.getColumnIndex("imoney");
					
					BigDecimal omoney = BigDecimal.ZERO;
					BigDecimal pmoney = BigDecimal.ZERO;
					BigDecimal imoney = BigDecimal.ZERO;
					String name = "";
										
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = c.getString(categoryIdx);
						omoney = new BigDecimal(c.getString(omoneyIdx));
						pmoney = new BigDecimal(c.getString(pmoneyIdx));
						imoney = new BigDecimal(c.getString(imoneyIdx));
						data.setCategory(name);
						
						omoney = omoney.add(pmoney);
						
						data.setMoney(omoney.toString());
						
						boolean flag = false;
						
						for (int j = 0; j < list.size(); j++)
						{
							if (data.getCategory().equals(list.get(j).getCategory()))
							{
								BigDecimal tempMoney = new BigDecimal(list.get(j).getMoney());
								
								list.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
								
								flag = true;
							}
						}
						
						if (flag == false)
						{
							list.add(data);
						}
						
						c.moveToNext();
					}
				}
			});
		}
		else if (inoutFlag == StatsActivity.STATS_ASSET_MANAGER)
		{
			Intent intent = getIntent();
			
			typeFlag = intent.getIntExtra(StatsAssetActivity.TYPE_FLAG, 0);
			assetFlag = intent.getIntExtra(StatsAssetActivity.ASSET_FLAG, 0);
			
			String query = "";
			
			String subQuery = "";
			
			if (assetFlag == 0)
			{
				getBankBook();
				
				if (typeFlag != 2)
				{
					subQuery += "and type = " + 
							BDConstents.BANK_TYPE + 
							" ";
				}
				else
				{
					subQuery += "and linktype = " + 
							BDConstents.BANK_TYPE + 
							" ";
				}
			}
			else if (assetFlag == 1)
			{
				getCheckCard();
				
				if (typeFlag != 2)
				{
					subQuery += "and type = " + 
							BDConstents.CHECK_TYPE +  
							" ";
				}
				else
				{
					subQuery += "and linktype = " + 
							BDConstents.CHECK_TYPE +  
							" ";
				}
			}
			else if (assetFlag == 2)
			{
				/** 시작일로 카드대금 가져올지 기간으로 가져올지 플래그 */
				int postCheck = pref.getInt(BDConstents.MONTH_POSTMONEY_SETTING, 0);
				
				if (postCheck != 0)
				{
					setPostMoneyTerm();
					return;
				}
				else
				{
					if (typeFlag != 2)
					{
						subQuery += "and type = " + 
								BDConstents.CREDIT_TYPE +  
								" ";
					}
					else
					{
						subQuery += "and linktype = " + 
								BDConstents.CREDIT_TYPE +  
								" ";
					}
					
					getCreditCard();
				}
			}
			else if (assetFlag == 3)
			{
				getRealMoney(firstDate, lastDate);
				return;
			}
			
			String where = "";
			
			for (int i = 0; i < moneyKinds.size(); i++)
			{
				if (i == moneyKinds.size()-1)
				{
					where = where + "'" + moneyKinds.get(i) + "'";
				}
				else
				{
					where = where + "'" + moneyKinds.get(i) + "', ";
				}
			}
			
			subQuery += "and moneykind in (" + where + ") ";
			
			if (typeFlag == 0)
			{
				query = "SELECT moneykind, category, SUM(omoney) omoney, SUM(pmoney) pmoney " +
						"FROM " +
						"(SELECT moneykind, category, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE " +
						"inmoney in ('0') and (outmoney not in ('0') or postmoney not in ('0')) and date >= " +
						firstDate + " and date <= " +
						lastDate + " " + subQuery + 
						"GROUP BY moneykind " +
						"UNION ALL " +
						"SELECT moneykind, category, SUM(outmoney) omoney, " +
						"SUM(postmoney) pmoney FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and category in ('" 
						+ BDConstents.CATEGORY_SUSUMONEY + "') GROUP BY moneykind) GROUP BY moneykind";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int moneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						int categoryIdx = c.getColumnIndex("category");
						
						BigDecimal money = BigDecimal.ZERO;
						BigDecimal pmoney = BigDecimal.ZERO;
						String name = "";
						String moneykind = "";
											
						
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(categoryIdx);
							moneykind = c.getString(moneyKindIdx);
							
							String errormoney = c.getString(moneyIdx);
							
							money = new BigDecimal(c.getString(moneyIdx));
							pmoney = new BigDecimal(c.getString(pmoneyIdx));
							data.setMoneyKind(moneykind);
							data.setCategory(name);
							data.setMoney(money.add(pmoney).toString());
							list.add(data);
							
							c.moveToNext();
						}
					}
				});
			}
			else if (typeFlag == 1)
			{
				query = "SELECT moneykind, SUM(inmoney) money FROM in_out " +
						"WHERE inmoney not in ('0') and date >= " +
						firstDate + " and date <= " +
						lastDate + " " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int moneyIdx = c.getColumnIndex("money");
						
						BigDecimal money = BigDecimal.ZERO;
						String name = "";
						
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							money = new BigDecimal(c.getString(moneyIdx));
							data.setMoneyKind(name);
							data.setMoney(money.toString());
							list.add(data);
							
							c.moveToNext();
						}
						
					}
				});
			}
			else if (typeFlag == 2)
			{
				query = "SELECT moneykind, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and type = " + 
						BDConstents.INOUT_TYPE + " " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int omoneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						
						BigDecimal omoney = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							omoney = new BigDecimal(c.getString(omoneyIdx));
							omoney = omoney.add(new BigDecimal(c.getString(pmoneyIdx)));
							data.setMoneyKind(name);
							
							data.setMoney(omoney.toString());
							list.add(data);
							
							c.moveToNext();
						}
					}
				});
				
				query = "SELECT moneykind, SUM(inmoney) imoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and type = " + 
						BDConstents.OUTIN_TYPE + " " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int imoneyIdx = c.getColumnIndex("imoney");
						
						BigDecimal imoney = BigDecimal.ZERO;
						String name = "";
											
						
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							imoney = new BigDecimal(c.getString(imoneyIdx));
							data.setMoneyKind(name);
							
							data.setMoney(imoney.toString());
							
							boolean flag = false;
							
							for (int j = 0; j < list.size(); j++)
							{
								if (data.getMoneyKind().equals(list.get(j).getMoneyKind()))
								{
									BigDecimal tempMoney = new BigDecimal(list.get(j).getMoney());
									
									list.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
									
									flag = true;
								}
							}
							
							if (flag == false)
							{
								list.add(data);
							}
							
							c.moveToNext();
						}
					}
				});
				
				query = "SELECT type, moneykind, SUM(outmoney) omoney, " +
						"SUM(inmoney) imoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and type = " + 
						BDConstents.MYBANK_INOUT_TYPE + " " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int omoneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						int imoneyIdx = c.getColumnIndex("imoney");
						
						BigDecimal omoney = BigDecimal.ZERO;
						BigDecimal pmoney = BigDecimal.ZERO;
						BigDecimal imoney = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							omoney = new BigDecimal(c.getString(omoneyIdx));
							pmoney = new BigDecimal(c.getString(pmoneyIdx));
							imoney = new BigDecimal(c.getString(imoneyIdx));
							data.setMoneyKind(name);
							
							omoney = omoney.add(pmoney);
							
							data.setMoney(omoney.toString());
							
							boolean flag = false;
							
							for (int j = 0; j < list.size(); j++)
							{
								if (data.getMoneyKind().equals(list.get(j).getMoneyKind()))
								{
									BigDecimal tempMoney = new BigDecimal(list.get(j).getMoney());
									
									list.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
									
									flag = true;
								}
							}
							
							if (flag == false)
							{
								list.add(data);
							}
							
							c.moveToNext();
						}
					}
				});
			}
		}
	}
	
	/**
	 * 현금의 내역을 가져온다.
	 * @param firstDate
	 * @param lastDate
	 */
	private void getRealMoney(String firstDate, String lastDate)
	{
		String subQuery = "and type = 0 ";
		
		String query = "";
		
		if (typeFlag == 0)
		{
			query = "SELECT type, category, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
					"FROM in_out WHERE " +
					"inmoney in ('0') and (outmoney not in ('0') or postmoney not in ('0')) and date >= " +
					firstDate + " and date <= " +
					lastDate + " and type not in (" + 
					BDConstents.INOUT_TYPE + ", " +
					BDConstents.OUTIN_TYPE + ", " +
					BDConstents.MYBANK_INOUT_TYPE + ") " + subQuery +
					"GROUP BY type "
					+ "UNION ALL "
					+ "SELECT moneykind, category, SUM(outmoney) omoney, " +
					"SUM(postmoney) pmoney FROM in_out WHERE date >= " +
					firstDate + " and date <= " +
					lastDate + " and category in ('" 
					+ BDConstents.CATEGORY_SUSUMONEY + "') " + subQuery + "GROUP BY type";
			
			sql.selectMapTile(this, query, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int moneyKindIdx = c.getColumnIndex("moneykind");
					int moneyIdx = c.getColumnIndex("omoney");
					int pmoneyIdx = c.getColumnIndex("pmoney");
					int categoryIdx = c.getColumnIndex("category");
					
					BigDecimal money = BigDecimal.ZERO;
					BigDecimal pmoney = BigDecimal.ZERO;
					String name = "";
					String moneykind = "";
										
					
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = c.getString(categoryIdx);
						moneykind = "현금";
						money = new BigDecimal(c.getString(moneyIdx));
						pmoney = new BigDecimal(c.getString(pmoneyIdx));
						data.setMoneyKind(moneykind);
						data.setCategory(name);
						data.setMoney(money.add(pmoney).toString());
						list.add(data);
						
						c.moveToNext();
					}
				}
			});
		}
		else if (typeFlag == 1)
		{
			query = "SELECT type, SUM(inmoney) money FROM in_out " +
					"WHERE inmoney not in ('0') and date >= " +
					firstDate + " and date <= " +
					lastDate + " and type not in (" + 
					BDConstents.INOUT_TYPE + ", " +
					BDConstents.OUTIN_TYPE + ", " +
					BDConstents.MYBANK_INOUT_TYPE + ") " + subQuery +
					"GROUP BY type;";
			
			sql.selectMapTile(this, query, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int moneyKindIdx = c.getColumnIndex("moneykind");
					int moneyIdx = c.getColumnIndex("money");
					
					BigDecimal money = BigDecimal.ZERO;
					String name = "";
					
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = "현금";
						money = new BigDecimal(c.getString(moneyIdx));
						data.setMoneyKind(name);
						data.setMoney(money.toString());
						list.add(data);
						
						c.moveToNext();
					}
					
				}
			});
		}
		else if (typeFlag == 2)
		{
			query = "SELECT type, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
					"FROM in_out WHERE date >= " +
					firstDate + " and date <= " +
					lastDate + " and type = " + 
					BDConstents.INOUT_TYPE + " " + 
					"GROUP BY type;";
			
			sql.selectMapTile(this, query, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int typeIdx = c.getColumnIndex("type");
					int omoneyIdx = c.getColumnIndex("omoney");
					int pmoneyIdx = c.getColumnIndex("pmoney");
					
					BigDecimal omoney = BigDecimal.ZERO;
					String name = "";
										
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = BDConstents.BANK_TO_REAL;
						omoney = new BigDecimal(c.getString(omoneyIdx));
						omoney = omoney.add(new BigDecimal(c.getString(pmoneyIdx)));
						data.setMoneyKind(name);
						
						data.setMoney(omoney.toString());
						list.add(data);
						
						c.moveToNext();
					}
				}
			});
			
			query = "SELECT type, SUM(inmoney) imoney " +
					"FROM in_out WHERE date >= " +
					firstDate + " and date <= " +
					lastDate + " and type = " + 
					BDConstents.OUTIN_TYPE + " " + 
					"GROUP BY type;";
			
			sql.selectMapTile(this, query, new ParseSelectData()
			{
				@Override
				public void resultData(Cursor c)
				{
					int typedx = c.getColumnIndex("type");
					int imoneyIdx = c.getColumnIndex("imoney");
					
					BigDecimal imoney = BigDecimal.ZERO;
					String name = "";
										
					
					c.moveToFirst();
					
					for (int i = 0; i < c.getCount(); i++)
					{
						StatsCategoryData data = new StatsCategoryData();
						name = BDConstents.REAL_TO_BANK;
						imoney = new BigDecimal(c.getString(imoneyIdx));
						data.setMoneyKind(name);
						
						data.setMoney(imoney.toString());
						
						boolean flag = false;
						
						for (int j = 0; j < list.size(); j++)
						{
							if (data.getMoneyKind().equals(list.get(j).getMoneyKind()))
							{
								BigDecimal tempMoney = new BigDecimal(list.get(j).getMoney());
								
								list.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
								
								flag = true;
							}
						}
						
						if (flag == false)
						{
							list.add(data);
						}
						
						c.moveToNext();
					}
				}
			});
		}
	}

	/**
	 * 카드 사용 일자로 카드 사용 금액을 가져온다.
	 */
	private void setPostMoneyTerm()
	{
		creditResultList = new ArrayList<CreditCardResultDateData>();
		
		sql.selectMapTile(this, "SELECT * FROM credit_card_result_date;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int idIdx = c.getColumnIndex("id");
				int nameIdx = c.getColumnIndex("name");
				int autoynIdx = c.getColumnIndex("autoyn");
				int startdateIdx = c.getColumnIndex("startdate");
				int enddateIdx = c.getColumnIndex("enddate");
				int resultdateIdx = c.getColumnIndex("resultdate");
				int resultflagIdx = c.getColumnIndex("resultflag");
				int linkidIdx = c.getColumnIndex("linkid");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					CreditCardResultDateData creditResultData = new CreditCardResultDateData();
					
					creditResultData.setId(c.getInt(idIdx) + "");
					creditResultData.setName(c.getString(nameIdx));
					creditResultData.setAutoyn(c.getInt(autoynIdx) + "");
					creditResultData.setStartdate(c.getInt(startdateIdx) + "");
					creditResultData.setEnddate(c.getInt(enddateIdx) + "");
					creditResultData.setResultdate(c.getInt(resultdateIdx) + "");
					creditResultData.setResultflag(c.getInt(resultflagIdx) + "");
					creditResultData.setLinkid(c.getInt(linkidIdx) + "");
					moneyKinds.add(creditResultData.getName());
					
					creditResultList.add(creditResultData);
					
					c.moveToNext();
				}
			}
		});
		
		for (int i = 0; i < creditResultList.size(); i++)
		{
			CreditCardResultDateData data = creditResultList.get(i);
			
			String moneykind = data.getName();
			
			int startDay = Integer.parseInt(data.getStartdate());
			int endDay = Integer.parseInt(data.getEnddate());
			
			String firstDate = "";
			String lastDate = "";
			
			if (date >= startDay)
			{
				firstDate = BDUtil.getDateDB(year, month+1, startDay);
						
				if (startDay == 1)
				{
					firstDate = BDUtil.getDateDB(year, month+1, startDay);
					lastDate = BDUtil.getDateDB(year, month+1, endDay);
				}
				else if (month == 11)
				{
					firstDate = BDUtil.getDateDB(year, month+1, startDay);
					lastDate = BDUtil.getDateDB(year+1, 1, endDay);
				}
				else
				{
					firstDate = BDUtil.getDateDB(year, month+1, startDay);
					lastDate = BDUtil.getDateDB(year, month+2, endDay);
				}
			}
			else
			{
				if (startDay == 1)
				{
					firstDate = BDUtil.getDateDB(year, month, endDay);
					lastDate = BDUtil.getDateDB(year, month, endDay);
				}
				else if (month == 0)
				{
					firstDate = BDUtil.getDateDB(year-1, 12, startDay);
					lastDate = BDUtil.getDateDB(year, month+1, endDay);
				}
				else
				{
					firstDate = BDUtil.getDateDB(year, month, startDay);
					lastDate = BDUtil.getDateDB(year, month+1, endDay);
				}
			}
			
			if (firstDate.equals(""))
			{
				continue;
			}
			
			String subQuery = "and moneykind = '" + BDUtil.getApostrophe(moneykind) + "' ";
			
			if (typeFlag != 2)
			{
				subQuery += "and type = " + 
						BDConstents.CREDIT_TYPE + 
						" ";
			}
			else
			{
				subQuery += "and linktype = " + 
						BDConstents.CREDIT_TYPE + 
						" ";
			}
			
			String query = "";
			
			if (typeFlag == 0)
			{
				query = "SELECT moneykind, category, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE " +
						"inmoney in ('0') and (outmoney not in ('0') or postmoney not in ('0')) and date >= " +
						firstDate + " and date <= " +
						lastDate + " and type not in (" + 
						BDConstents.INOUT_TYPE + ", " +
						BDConstents.OUTIN_TYPE + ", " +
						BDConstents.MYBANK_INOUT_TYPE + ") " + subQuery +
						"GROUP BY moneykind "
						+ "UNION ALL "
						+ "SELECT moneykind, category, SUM(outmoney) omoney, " +
						"SUM(postmoney) pmoney FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and category in ('" 
						+ BDConstents.CATEGORY_SUSUMONEY + "') " + subQuery + "GROUP BY moneykind";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int moneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						int categoryIdx = c.getColumnIndex("category");
						
						BigDecimal money = BigDecimal.ZERO;
						BigDecimal pmoney = BigDecimal.ZERO;
						String name = "";
						String moneykind = "";
											
						
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(categoryIdx);
							moneykind = c.getString(moneyKindIdx);
							money = new BigDecimal(c.getString(moneyIdx));
							pmoney = new BigDecimal(c.getString(pmoneyIdx));
							data.setMoneyKind(moneykind);
							data.setCategory(name);
							data.setMoney(money.add(pmoney).toString());
							list.add(data);
							
							c.moveToNext();
						}
					}
				});
			}
			else if (typeFlag == 1)
			{
				query = "SELECT moneykind, SUM(inmoney) money FROM in_out " +
						"WHERE inmoney not in ('0') and date >= " +
						firstDate + " and date <= " +
						lastDate + " and type not in (" + 
						BDConstents.INOUT_TYPE + ", " +
						BDConstents.OUTIN_TYPE + ", " +
						BDConstents.MYBANK_INOUT_TYPE + ") " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int moneyIdx = c.getColumnIndex("money");
						
						BigDecimal money = BigDecimal.ZERO;
						String name = "";
						
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							money = new BigDecimal(c.getString(moneyIdx));
							data.setMoneyKind(name);
							data.setMoney(money.toString());
							list.add(data);
							
							c.moveToNext();
						}
						
					}
				});
			}
			else if (typeFlag == 2)
			{
				query = "SELECT moneykind, SUM(outmoney) omoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and type = " + 
						BDConstents.INOUT_TYPE + " " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int omoneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						
						BigDecimal omoney = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							omoney = new BigDecimal(c.getString(omoneyIdx));
							omoney = omoney.add(new BigDecimal(c.getString(pmoneyIdx)));
							data.setMoneyKind(name);
							
							data.setMoney(omoney.toString());
							list.add(data);
							
							c.moveToNext();
						}
					}
				});
				
				query = "SELECT moneykind, SUM(inmoney) imoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and type = " + 
						BDConstents.OUTIN_TYPE + " " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int imoneyIdx = c.getColumnIndex("imoney");
						
						BigDecimal imoney = BigDecimal.ZERO;
						String name = "";
											
						
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							imoney = new BigDecimal(c.getString(imoneyIdx));
							data.setMoneyKind(name);
							
							data.setMoney(imoney.toString());
							
							boolean flag = false;
							
							for (int j = 0; j < list.size(); j++)
							{
								if (data.getMoneyKind().equals(list.get(j).getMoneyKind()))
								{
									BigDecimal tempMoney = new BigDecimal(list.get(j).getMoney());
									
									list.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
									
									flag = true;
								}
							}
							
							if (flag == false)
							{
								list.add(data);
							}
							
							c.moveToNext();
						}
					}
				});
				
				query = "SELECT type, moneykind, SUM(outmoney) omoney, " +
						"SUM(inmoney) imoney, SUM(postmoney) pmoney " +
						"FROM in_out WHERE date >= " +
						firstDate + " and date <= " +
						lastDate + " and type = " + 
						BDConstents.MYBANK_INOUT_TYPE + " " + subQuery +
						"GROUP BY moneykind;";
				
				sql.selectMapTile(this, query, new ParseSelectData()
				{
					@Override
					public void resultData(Cursor c)
					{
						int moneyKindIdx = c.getColumnIndex("moneykind");
						int omoneyIdx = c.getColumnIndex("omoney");
						int pmoneyIdx = c.getColumnIndex("pmoney");
						int imoneyIdx = c.getColumnIndex("imoney");
						
						BigDecimal omoney = BigDecimal.ZERO;
						BigDecimal pmoney = BigDecimal.ZERO;
						BigDecimal imoney = BigDecimal.ZERO;
						String name = "";
											
						c.moveToFirst();
						
						for (int i = 0; i < c.getCount(); i++)
						{
							StatsCategoryData data = new StatsCategoryData();
							name = c.getString(moneyKindIdx);
							omoney = new BigDecimal(c.getString(omoneyIdx));
							pmoney = new BigDecimal(c.getString(pmoneyIdx));
							imoney = new BigDecimal(c.getString(imoneyIdx));
							data.setMoneyKind(name);
							
							omoney = omoney.add(pmoney);
							
							data.setMoney(omoney.toString());
							
							boolean flag = false;
							
							for (int j = 0; j < list.size(); j++)
							{
								if (data.getMoneyKind().equals(list.get(j).getMoneyKind()))
								{
									BigDecimal tempMoney = new BigDecimal(list.get(j).getMoney());
									
									list.get(j).setMoney(tempMoney.add(new BigDecimal(data.getMoney())).toString());
									
									flag = true;
								}
							}
							
							if (flag == false)
							{
								list.add(data);
							}
							
							c.moveToNext();
						}
					}
				});
			}
		}
	}
	
	private void getBankBook()
	{
		moneyKinds = new ArrayList<String>();
		
		sql.selectMapTile(superContext, "SELECT name FROM bankbook;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int nameIdx = c.getColumnIndex("name");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					String name = c.getString(nameIdx);
					moneyKinds.add(name);
					c.moveToNext();
				}
			}
		});
	}

	private void getCheckCard()
	{
		moneyKinds = new ArrayList<String>();
		
		sql.selectMapTile(superContext, "SELECT name FROM check_card;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int nameIdx = c.getColumnIndex("name");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					String name = c.getString(nameIdx);
					moneyKinds.add(name);
					c.moveToNext();
				}
			}
		});
	}

	private void getCreditCard()
	{
		moneyKinds = new ArrayList<String>();
		
		sql.selectMapTile(superContext, "SELECT name FROM credit_card;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int nameIdx = c.getColumnIndex("name");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					String name = c.getString(nameIdx);
					moneyKinds.add(name);
					c.moveToNext();
				}
			}
		});
	}

	private void startLeftMonthButton()
	{
		if (month == 0)
		{
			year--;
			month = 11;
		}
		else
		{
			month--;
		}
		
		BDUtil.startLeftDegrees(dateTextView).setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}
			
			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}
			
			@Override
			public void onAnimationEnd(Animation animation)
			{
				dateTextView.setText(year + "년 " + (month+1) + "월");
				setData(inoutFlag);
			}
		});
	}
	
	private void startRightMonthButton()
	{
		if (month == 11)
		{
			year++;
			month = 0;
		}
		else
		{
			month++;
		}
		
		BDUtil.startRightDegrees(dateTextView).setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
			}
			
			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}
			
			@Override
			public void onAnimationEnd(Animation animation)
			{
				dateTextView.setText(year + "년 " + (month+1) + "월");
				setData(inoutFlag);
			}
		});
	}
	
	/**
	 * 다이얼로그 뛰우기 
	 */
	private class ShowDialog extends AsyncTask<Integer, Integer, Integer>{
		ProgressDialog dialog = null;
		
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			dialog = new ProgressDialog(StatsCategoryActivity.this);
			dialog.setCancelable(false);
			dialog.setMessage("Loading...");
			dialog.show();
		}
		
		@Override
		protected Integer doInBackground(Integer... arg0) {
			
			if (arg0[0] == 0)
			{
				getCategoryData();
				return 0;
			}
			
			return null;
		}

		@Override
		protected void onPostExecute(Integer result) {
			super.onPostExecute(result);
			
			dialog.dismiss();
			
			if (result == 0)
			{
				setStatsData();
			}
		}
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(this, TipInfoActivity.class);
		intent.putExtra(TipsActivity.TIP_REQUEST_KEY, TipsActivity.TIP_STATS);
		startActivity(intent);
	}
}
